package com.kool.kadmin.mqtt.controller;

import com.kool.kadmin.common.bean.PageListResult;
import com.kool.kadmin.common.bean.Result;
import com.kool.kadmin.common.util.ResultUtil;
import com.kool.kadmin.mqtt.request.AddClientReq;
import com.kool.kadmin.mqtt.request.DeleteClientReq;
import com.kool.kadmin.mqtt.request.GetClientPageReq;
import com.kool.kadmin.mqtt.request.UpdateClientReq;
import com.kool.kadmin.mqtt.service.MqttClientService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author luyu
 * @date 2021-04-17 19:16
 */
@RestController
public class ClientController {
    @Resource
    private MqttClientService clientService;

    /**
     * 分页查询客户端设备信息
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/getClientPage")
    public PageListResult getClientPage(@RequestBody @Valid GetClientPageReq request) {
        return clientService.getClientPage(request);
    }

    /**
     * 新增客户端设备信息
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/addClient")
    public Result addClient(@RequestBody @Valid AddClientReq request) {
        clientService.addClient(request);
        return ResultUtil.success();
    }

    /**
     * 更新客户端设备信息
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/updateClient")
    public Result updateClient(@RequestBody @Valid UpdateClientReq request) {
        clientService.updateClient(request);
        return ResultUtil.success();
    }

    /**
     * 删除客户端设备信息
     *
     * @param request
     * @return
     */
    @PostMapping("/mqtt/deleteClient")
    public Result deleteClient(@RequestBody @Valid DeleteClientReq request) {
        clientService.deleteClient(request);
        return ResultUtil.success();
    }
}
